package leetcode.code2104;

import leetcode.IDebug;

public class Solution implements IDebug {

//	int Max = (int) 1e9 + 1;
//	int Min = -Max;

	public long subArrayRanges(int[] nums) {
		long ans = 0;
		int len = nums.length;
		for (int i = 1; i < len; i++) {
			int max = nums[i], min = nums[i];
			for (int j = i - 1; j >= 0; j--) {
				int cur = nums[j];
				max = Math.max(max, cur);
				min = Math.min(min, cur);
				ans += max - min;
			}
		}
		return ans;
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
